package edu.calpoly.csc.coursebook.business.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;

import edu.calpoly.csc.coursebook.business.db.CourseManagerDao;
import edu.calpoly.csc.coursebook.util.KeywordExtractor;
import edu.calpoly.csc.coursebook.util.impl.WordNetKeywordExtractor;

public class CourseManager implements Serializable
{
   private CourseManagerDao cmd;
   private Collection<Course> courses;
   
   public void setCourseManagerDao(CourseManagerDao cmd)
   {
      this.cmd = cmd;
   }
   
   public Collection<Course> getCourses()
   {
      this.courses = cmd.getCoursesList();
      return this.courses;
   }
   
   public Collection<Course> findCourses(String interests)
   {
      KeywordExtractor extractor = WordNetKeywordExtractor.getInstance();
      HashMap<String, Double> keywords = extractor.extractKeywords(interests);
      return cmd.getCoursesList(keywords, extractor.getOriginalInterestKeywords(), 
    		  extractor.getInterestToSynonymMap());
   }
   
   /**
    * Adds <code>units</code> units to each course in this manager. 
    * @param units
    */
   public void increaseUnits(int units)
   {
      Collection<Course> courses = cmd.getCoursesList();
      for(Course c : courses)
	 cmd.increaseUnits(c, units);
   }
   
   public Collection<String> getKeywords() {
	   KeywordExtractor extractor = WordNetKeywordExtractor.getInstance();
	   return extractor.getOriginalInterestKeywords();
   }
}
